package cst.a316yzy.recyclerview316;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initRecyclerView();
        }


        private List<ArticleBean> getData() {
            List<ArticleBean> list = new ArrayList<ArticleBean>();
            ArticleBean art;

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题1");
            art.setImgid(R.drawable.f1);
            art.setTime("2017-4-1 15:16");
            art.setDescription("嘿");
            list.add(art);

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题2");
            art.setImgid(R.drawable.f2);
            art.setTime("2017-4-1 15:16");
            art.setDescription("吼");
            list.add(art);

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题3");
            art.setImgid(R.drawable.f3);
            art.setTime("2017-4-1 15:16");
            art.setDescription("哈");
            list.add(art);

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题4");
            art.setImgid(R.drawable.f4);
            art.setTime("2017-4-1 15:16");
            art.setDescription("哦");
            list.add(art);

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题5");
            art.setImgid(R.drawable.f5);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述5");
            list.add(art);

            art = new ArticleBean();
            art.setArticleId(1);
            art.setTitle("标题6");
            art.setImgid(R.drawable.f6);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述6");
            list.add(art);

            return list;

        }

        private RecyclerView recyclerView;
        private RecyclerView.LayoutManager layoutManager;
        private MyAdapter mAdapter;
        List<ArticleBean> list;
        private void initRecyclerView() {
            recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
            layoutManager = new LinearLayoutManager(this);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setHasFixedSize(true);
            list = getData();
            mAdapter = new MyAdapter(this);
            mAdapter.setList(list);
            recyclerView.setAdapter(mAdapter);
        }
    }


